(function($){
    function initSetState() {
        $('.but_set_state').on('click', function(){
            var obj = $(this);
            var state = obj.attr('dstate');
            var id = obj.attr('did');
            var url = obj.attr('durl');
            var info = '删除';
            switch(state) {
                case '-1':
                    info = '删除';
                    break;
                case '0':
                    info = '恢复';
                    break;
                case '1':
                    info = '发布';
                    break;
            }
            layer.confirm(
                '确定要从活动中【' + info + '】此美容院吗？',
                {
                    icon: 3,
                    title: '系统提示',
                    btn: ['确 定', '取 消']
                },
                function(index){
                    layer.close(index);
                    layer.load();
                    $.post(
                        url,
                        {id: id, state: state},
                        function(data){
                            if(data.status == 10000) {
                                location.reload(true);
                            } else {
                                layer.closeAll();
                                layer.alert(data.errmsg);
                            }
                        },
                        'json'
                    );
                },
                function(index){
                    layer.close(index);
                }
            );
        });
    }
    $(function(){
        initSetState();
    });
})(jQuery);